package com.yfyszk.kingbird.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 *
 * @author wgc
 * @since 2018-03-21
 */
@Slf4j
@EnableTransactionManagement
@Configuration
@MapperScan("com.yfyszk.kingbird.mapper")
public class MybatisPlusConfig {
    /**
     *   mybatis-plus分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor page = new PaginationInterceptor();
       // page.setLocalPage(true);
        page.setDialectType("mysql");
        return page;
    }

    @Bean(name = "transactionManager")
    public DataSourceTransactionManager transactionManager(DataSource dataSource) {
        log.info("开始启动事务:{}",dataSource);
        return new DataSourceTransactionManager(dataSource);
    }
}
